<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <s:head/>
</head>
<script type="text/javascript">
    var id = "${contacter.id}";
    var gridTitle = "";
    if (id) {
        gridTitle = "修改数据";
    } else {
        gridTitle = "添加数据";
    }
    var formSetting = {
        title: "基础数据",
        module: 'save',
        columns: [{
            name: "contacter.id",
            label: "id",
            hidden: true
        }, {
            name: "contacter.company",
            label: "工厂名称"
        }, {
            name: "contacter.city",
            label: "装柜地址：市",
            hidden: true
        }, {
            name: "contacter.cityId",
            label: "装柜地址：市",
            type: "dropdown",
            dropdownType: "ajax",
            nlabel: "contacter.city",
            url: "../base/address-dropdown?layer=2&code=44",
            sid: "0P",
            minLength: 0
        }, {
            name: "contacter.area",
            label: "装柜地址：区",
            hidden: true
        }, {
            name: "contacter.areaId",
            label: "装柜地址：区",
            type: "dropdown",
            dropdownType: "ajax",
            nlabel: "contacter.area",
            url: "../base/address-dropdown?layer=3",
            sid: "0C",
            minLength: 0
        }, {
            name: "contacter.town",
            label: "装柜地址：街道",
            hidden: true
        }, {
            name: "contacter.townId",
            label: "装柜地址：街道",
            type: "dropdown",
            dropdownType: "ajax",
            nlabel: "contacter.town",
            url: "../base/address-dropdown?layer=4",
            sid: "0",
            minLength: 0
        }, {
            name: "contacter.address",
            label: "装柜地址：详细地址"
        }, {
            name: "contacter.name",
            label: "联系人姓名"
        }, {
            name: "contacter.phone",
            label: "联系人电话"
        }],
        form: {
            'url': 'contacter-saveOrUpdate',
            'data': function () {
                var id = "${contacter.id}";
                if (id) {
                    var dataValue = "";
                    $.ajax({
                        url: "contacter-find?contacter.id=" + id,
                        async: false,
                        cache: false,
                        success: function (data) {
                            dataValue = data;
// 								if(data.contacter.cityId != null) {
                            var dropdownNameCity = $.mrdForm.getDropDwonLabelName("contacter.cityId");
                            data[dropdownNameCity] = data.contacter.city;
                            var dropdownNameArea = $.mrdForm.getDropDwonLabelName("contacter.areaId");
                            data[dropdownNameArea] = data.contacter.area;
                            var dropdownNameTown = $.mrdForm.getDropDwonLabelName("contacter.townId");
                            data[dropdownNameTown] = data.contacter.town;
// 								}
                        }
                    });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
            }
        },
        buttons: {
            custom: [
                {
                    id: "cancelbtn",
                    value: "返回",
                    click: function () {
                        //$('#center', window.parent.document).attr("src","province-main");
                        history.go(-1);
                    }
                }
            ]
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
    });
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
</body>
</html>
